//应急方案管理
Ext.define('Admin.view.emergencyDispatch.DdsEdP', {
    extend: "Admin.common.container.BaseContainer",
    xtype: 'ddsEdP',
    alias: 'ddsEdP',
    requires: ['Ext.panel.Panel', 'Ext.grid.Panel', 'Ext.button.Button', 'Admin.store.emergencyDispatch.DdsEdP'],
    controller: 'ddsEdPController',
    viewModel: "ddsEdPModel",
    layout: 'fit',
    width: '100%',
    height: 200,
    items: [{
        xtype: 'baseGridPanel',
        title: '应急方案管理',
        border: true,
        margin: '0 0 10 0',
        reference: 'ddsEdPGrid', //添加“reference”配置到表格并用lookupReference方法获取表格组件
        stripeRows: true, //斑马纹效果
        loadMask: true, //loading效果
        align: 'center',
        multiSelect: false, //允许用户在列表中同时选择多个
        listeners: {
            cellclick: 'onGridCellItemClick'
        },
        columns: [{
                text: '方案名称',
                dataIndex: 'proNm',
                flex: 1
            }, {
                text: '方案id',
                hidden: true,
                dataIndex: 'proCd',
                flex: 1
            }, {
                text: '事件名称',
                dataIndex: 'evenNm',
                flex: 1,
            }, {
                text: '事件类型',
                dataIndex: 'evenTp',
                flex: 1,
                renderer: function(value) {
                    for (var i = 0; i < dictList.length; i++) {
                        if (dictList[i].type === 'eventp' && dictList[i].value === value) {
                            return dictList[i].label;
                        }
                    }
                    // return dictList.filter(item => item.type==='eventp').filter(_ => _.value ==value)[0].label
                }
            }, {
                text: '发生时间',
                dataIndex: 'pubDt',
                flex: 1
            }, {
                text: '发生源位置',
                dataIndex: 'loc',
                flex: 1
            }, {
                text: '调度起始时间',
                dataIndex: 'bgDt',
                flex: 1
            }, {
                text: '调度结束时间',
                dataIndex: 'edDt',
                flex: 1
            }, {
                text: '编制时间',
                dataIndex: 'crDt',
                flex: 1
            }, {
                text: '时段类型',
                dataIndex: 'rgTp',
                flex: 1
            },
            {
                text: '执行人',
                dataIndex: 'producer',
                flex: 1
            },
            {
                text: '完成状态',
                dataIndex: 'sta',
                flex: 1,
                renderer: function(value, metaData, record, rowIndex) {
                    if (record.data.nt == 1) {
                        switch (value) {
                            case 1:
                                return '1/4';
                                // break;
                            case 2:
                                return '2/4';
                                // break;
                            case 3:
                                return '3/4';
                                // break;
                            case 4:
                                return '4/4';
                                // break;
                            default:
                                return '0/4';
                        }
                    } else {
                        switch (value) {
                            case 1:
                                return '1/5';
                                // break;
                            case 2:
                                return '2/5';
                                // break;
                            case 3:
                                return '3/5';
                                // break;
                            case 4:
                                return '4/5';
                                // break;
                            case 5:
                                return '5/5';
                                // break;
                            default:
                                return '0/5';
                        }
                    }
                }
            },
            {
                text: '备注',
                dataIndex: 'nt',
                flex: 1,
                hidden: true,
            },
            {
                xtype: "actionTextcolumn",
                text: "污染源信息",
                width: 120,
                sortable: false,
                menuDisabled: true,
                items: [{
                    showText: "调度方案",
                    handler: function(grid, rowIndex, colIndex) {
                        var data = grid.getStore().getAt(rowIndex).data;
                        if (!data.rcd) {
                            Ext.Msg.alert('系统提示', '请先追踪溯源后再进行应急调度!');
                            return;
                        }
                        if (data.nt == "1") { //水质模拟
                            config.waterQualityProCd = data.proCd;
                            window.location.hash = '#waterQuality';
                        } else if (data.nt == "2") { //水量调度
                            config.newPlanProCd = data.proCd;
                            window.location.hash = '#newPlan';
                        } else {
                            Ext.Msg.alert('系统提示', '跳转页面失败!');
                        }
                    }
                }, ]
            },
            {
                xtype: 'actioncolumn',
                text: '操作',
                align: 'center',
                // width: 100,
                sortable: false,
                menuDisabled: true,
                items: [{
                        iconCls: 'x-fa fa-edit',
                        tooltip: '编辑',
                        handler: 'onUpdataClick'
                    },
                    {
                        iconCls: 'x-fa fa-times-circle',
                        tooltip: '删除',
                        handler: 'onDelClick'
                    }
                ]
            }
        ],
        store: {
            type: 'ddsEdP'
        },
        tbar: [{
                xtype: "dicComboBox",
                dicType: 'incidentType',
                maxWidth: 160,
                fieldLabel: "事件类型",
                labelWidth: 60,
                reference: 'evenTp',
            },
            // {
            // 	xtype: "textfield",
            // 	maxWidth: 160,
            // 	fieldLabel: "发生区域",
            // 	labelWidth: 60,
            // 	reference: 'loc'
            // },
            // {
            //     xtype: "combobox",
            //     maxWidth: 220,
            //     fieldLabel: "发生区域",
            //     labelWidth: 60,
            //     reference: 'loc',
            //     displayField: 'loc',
            //     queryMode: 'local',
            //     valueField: 'loc',
            //     triggerAction: 'all',
            //     anyMatch: true,
            //     listeners: {
            //         added: function(combo) {
            //             var _that = this;
            //             var store = Ext.create("Ext.data.Store", {
            //                 autoLoad: true,
            //                 proxy: {
            //                     type: "ajax",
            //                     extraParams: { river: config.RIVER },
            //                     url: config.URL + "emergency/ddsEdEvent/list",
            //                     reader: {
            //                         type: "json",
            //                         rootProperty: "list",
            //                         fields: ["loc"]
            //                     }
            //                 }
            //             });
            //             console.log(store);
            //             combo.setStore(store);
            //         }
            //     }
            // },
            {
                xtype: "datefield",
                maxWidth: 200,
                fieldLabel: "编制时间",
                // editable: false,
                format: 'Y-m-d',
                labelWidth: 60,
                reference: 'startTime',
                listeners: {
                    change: function() {
                        var edDt = this.nextSibling().nextSibling();
                        edDt.setMinValue(this.value);
                    }
                }
            }, '--', {
                xtype: "datefield",
                maxWidth: 140,
                // editable: false,
                format: 'Y-m-d',
                reference: 'endTime'
            }, '->', {
                xtype: "button",
                text: "查询",
                iconCls: "x-fa fa-search",
                handler: 'onSearchClick'
            }, {
                xtype: "button",
                text: "新建方案",
                iconCls: "x-fa fa-file-o",
                handler: 'onAddClick'
            }
        ],
        dockedItems: [{
            xtype: 'pagingtoolbar',
            dock: 'bottom',
            itemId: 'pagingToolbar',
            displayInfo: true,
            bind: '{xx}'
        }]
    }, ]
});

//会商 新增/修改 form表单
Ext.define('Admin.view.emergencyDispatch.WarnForm', {
    extend: 'Admin.common.form.BaseFormPanel',
    xtype: 'warnForm',
    require: ['Admin.store.emergencyDispatch.NewPlanEventList'],
    alias: 'warnForm',
    bodyPadding: 10,
    layout: 'anchor',
    viewModel: "ddsEdPModel",
    defaults: {
        anchor: '100%',
        labelWidth: 60,
        collapsible: true,
    },
    items: [{
            xtype: 'fieldset',
            title: '基本信息',
            defaultType: 'textfield',
            layout: 'anchor',
            defaults: {
                anchor: '100%',
                labelAlign: 'right',
            },
            items: [{
                    xtype: 'textfield',
                    grow: true,
                    name: 'proNm',
                    fieldLabel: '方案名称',
                    reference: 'editEvenproNm',
                    allowBlank: false,
                    anchor: '100%'
                },
                {
                    xtype: 'textfield',
                    hidden: true,
                    name: 'proCd',
                    fieldLabel: '方案名称',
                    anchor: '100%'
                },
                {
                    xtype: "combobox",
                    fieldLabel: "选择应急事件",
                    reference: 'editEvenCd',
                    name: 'evenCd',
                    valueField: 'evenCd',
                    displayField: 'evenNm',
                    queryMode: 'remote', //数据从服务端读取
                    remoteFilter: true, //进一步过滤store
                    editable: false,
                    allowBlank: false,
                    bind: {
                        store: "{evenListStore}",
                        value: "{evenCd}"
                    },
                    listeners: {
                        change: 'evenCdchange'
                            // added: function(combo) {
                            //   var _that = this;
                            //   var store = Ext.create('Ext.data.Store', {
                            //       autoLoad: true,
                            //       proxy: {
                            //           type: 'ajax',
                            //           url: config.URL + "emergency/ddsEdEvent/list",
                            //           extraParams: {
                            //               river: config.RIVER
                            //           },
                            //           reader: {
                            //               type: 'json',
                            //               rootProperty: 'list',
                            //           }
                            //       }
                            //   });
                            // combo.setStore(store);
                            // }
                    }
                },
                {
                    xtype: 'textfield',
                    // format: "Y-m-d H:i:s",
                    fieldLabel: "发生时间",
                    name: 'pubDt',
                    reference: 'editEvenpubDt',
                    allowBlank: false,
                    editable: false,
                },
                // {
                // 	xtype: 'datetimefield',
                // 	format: "Y-m-d H:i:s",
                // 	fieldLabel: "发生时间",
                // 	name: 'hapDt',
                // 	bind: {
                // 		value: "{hapDt}"
                // 	},
                // 	allowBlank: false,
                // 	editable: false,
                // },
            ]
        },
        {
            xtype: 'fieldset',
            title: '时间设置',
            defaultType: 'textfield',
            layout: 'anchor',
            defaults: {
                labelAlign: 'right',
                anchor: '100%'
            },
            items: [{
                    xtype: 'timesfield',
                    format: "Y-m-d H:i:s",
                    fieldLabel: "起始时间",
                    name: 'bgDt',
                    allowBlank: false,
                    editable: false,
                    reference: 'WARN_FIELD_QSSJ',
                    listeners: {
                        // change: function() {
                        //     var edDt = this.nextSibling();
                        //     var minValue = edDt.minValue;
                        //     if (!minValue || minValue < this.value) {
                        //         edDt.setMinValue(this.value);
                        //     }
                        // }
                    }
                },
                {
                    xtype: 'timesfield',
                    format: "Y-m-d H:i:s",
                    fieldLabel: "终止时间",
                    name: 'edDt',
                    allowBlank: false,
                    editable: false,
                    reference: 'WARN_FIELD_ZZSJ'
                },
                {
                    xtype: "combobox",
                    fieldLabel: "时间类型",
                    reference: 'WARN_FIELD_SJCD',
                    forceSelect: true,
                    editable: false,
                    name: 'rgTp',
                    value: '小时',
                    valueField: "label",
                    displayField: "label",
                    store: {
                        fields: ["label", "value"],
                        data: [{
                            label: "小时",
                            value: 1
                        }]
                    }
                },
                {
                    fieldLabel: "预热期",
                    name: 'forTime',
                    allowBlank: false,
                    reference: 'WARN_FIELD_YRQ'
                }
            ]
        },
        {
            xtype: 'textfield',
            name: 'conId',
            hidden: true
        }
    ]
});